package cn.iocoder.yudao.module.nmkj.service.teamintroduce;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import cn.iocoder.yudao.module.nmkj.controller.admin.teamintroduce.vo.*;
import cn.iocoder.yudao.module.nmkj.dal.dataobject.teamintroduce.TeamIntroduceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.nmkj.dal.mysql.teamintroduce.TeamIntroduceMapper;

import java.util.Collections;
import java.util.List;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.TEAM_INTRODUCE_NOT_EXISTS;

/**
 * 团队介绍 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class TeamIntroduceServiceImpl implements TeamIntroduceService {

    @Resource
    private TeamIntroduceMapper teamIntroduceMapper;

    @Override
    public Long createTeamIntroduce(TeamIntroduceSaveReqVO createReqVO) {
        // 插入
        TeamIntroduceDO teamIntroduce = BeanUtils.toBean(createReqVO, TeamIntroduceDO.class);
        teamIntroduceMapper.insert(teamIntroduce);
        // 返回
        return teamIntroduce.getId();
    }

    @Override
    public void updateTeamIntroduce(TeamIntroduceSaveReqVO updateReqVO) {
        // 校验存在
        validateTeamIntroduceExists(updateReqVO.getId());
        // 更新
        TeamIntroduceDO updateObj = BeanUtils.toBean(updateReqVO, TeamIntroduceDO.class);
        teamIntroduceMapper.updateById(updateObj);
    }

    @Override
    public void deleteTeamIntroduce(Long id) {
        // 校验存在
        validateTeamIntroduceExists(id);
        // 删除
        teamIntroduceMapper.deleteById(id);
    }

    private void validateTeamIntroduceExists(Long id) {
        if (teamIntroduceMapper.selectById(id) == null) {
            throw exception(TEAM_INTRODUCE_NOT_EXISTS);
        }
    }

    @Override
    public TeamIntroduceDO getTeamIntroduce(Long id) {
        return teamIntroduceMapper.selectById(id);
    }

    @Override
    public PageResult<TeamIntroduceDO> getTeamIntroducePage(TeamIntroducePageReqVO pageReqVO) {
        return teamIntroduceMapper.selectPage(pageReqVO);
    }

    @Override
    public List<TeamIntroduceDO> getTeamIntroduceList(TeamIntroducePageReqVO reqVO) {
        return teamIntroduceMapper.selectList(reqVO);
    }

}